package cn.ibobo.lease.app.service.impl;

import cn.ibobo.lease.app.dao.BusinessMapper;
import cn.ibobo.lease.app.service.BusinessService;
import cn.ibobo.lease.common.base.BaseMapper;
import cn.ibobo.lease.common.base.BaseServiceImpl;
import cn.ibobo.lease.common.dto.BusinessDTO;
import cn.ibobo.lease.common.util.UuidUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;


/**
 * 商户表业务处理接口
 * @Author lililiang
 * @Date 2018-12-13 18:38:03
 */
@Service
public class BusinessServiceImpl extends BaseServiceImpl<BusinessDTO, String> implements BusinessService {

    private static final Log LOGGER = LogFactory.getLog(BusinessServiceImpl.class);

    @Autowired
    private BusinessMapper mapper;

    @Override
    protected BaseMapper<BusinessDTO, String> getMapper() {
        return mapper;
    }

    /**
     * 商户表列表
     * @Author lililiang
     * @Date 2018-12-13 18:38:03
     * @Param
     * @Return
     */
    @Override
    public List<BusinessDTO> list4Page(BusinessDTO entity, Integer pageNum, Integer... pageSize) {
        return super.list4Page(entity, pageNum, pageSize);
    }

    /**
     * 商户表列表（无分页）
     * @Author lililiang
     * @Date 2018-12-13 18:38:03
     * @Param
     * @Return
     */
    @Override
    public List<BusinessDTO> listByCondition(BusinessDTO entity) {
        return super.listByCondition(entity);
    }

    /**
     * 查询商户表详情信息
     * @Author lililiang
     * @Date 2018-12-13 18:38:03
     * @Param
     * @Return
     */
    @Override
    public BusinessDTO queryOneByPk(String id) {
        return super.queryOneByPk(id);
    }

    /**
     * 保存商户表信息
     * @Author lililiang
     * @Date 2018-12-13 18:38:03
     * @Param
     * @Return
     */
    @Override
    @Transactional
    public Integer save(BusinessDTO entity) {
        String bid = entity.getBid();
        if(bid == null || bid.length() == 0){
            entity.setBid(UuidUtil.getUuid());
            return mapper.add(entity);
        }else{
            return mapper.edit(entity);
        }
    }

    /**
     * 删除商户表信息
     * @Author lililiang
     * @Date 2018-12-13 18:38:03
     * @Param
     * @Return
     */
    @Override
    @Transactional
    public Integer delete(String id) {
        return super.delete(id);
    }
}
